package com.example.elemboot.Controller;

import com.example.elemboot.Entity.*;
import com.example.elemboot.Service.IOrderService;
import com.example.elemboot.Utils.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Resource
    private IOrderService orderService;

    @PostMapping("/createOrders")
    public Result createOrders(@RequestParam("orderTotal") Double orderTotal,
                               @RequestParam("userPhone") String userPhone,
                               @RequestParam("daId") Integer daId,
                               @RequestParam("businessId") Integer businessId
    ){
        Orders orders = orderService.createOrders(orderTotal, userPhone, daId, businessId);
        return Result.success(orders.getOrderId());
    }

    @GetMapping("/listOrdersByUserId/{userPhone}")
    public Result listOrdersByUserId(@PathVariable("userPhone") String userPhone){
        List<Orders> ordersList = orderService.listOrdersByUserId(userPhone);
        return Result.success(ordersList);
    }

    @GetMapping("/getOrdersById/{orderid}")
    public Result getOrdersById(@PathVariable("orderid") Integer orderid){
        Orders orders = orderService.getOrdersById(orderid);
        return Result.success(orders);
    }

    @PostMapping("/updateOrderState")
    public Result updateOrderState(@RequestParam("orderId") Integer orderId){
        Boolean state = orderService.updateOrderState(orderId);
        if (state){
            return Result.success("支付成功");
        }
        return Result.success("支付失败");

    }

}
